﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
namespace WPFExcelReport
{
    public partial class UIWTGEW : ViewBase
    {
       
      
        public VWTGEW TMV
        {
            get
            {
                return (VWTGEW)MV;
            }
        }
        public UIWTGEW()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
        }

        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            base.Window_Loaded(sender, e);

        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);

            if (dwMaster == null)
            {
                GFDISM = 0.0; 
                WEAVE = "".PadRight(15);
                PEGPLAN = "".PadRight(15);
                WTKEY = "".PadRight(15);
            }
            else
            {
                GFDISM = TMV.WTGFDISM;
                GWBBRT = TMV.WTGWBBRT;
                GWBF = TMV.WTGWBF;
                FTOLM=TMV.WTGNFTOLM;
                FTOLP=TMV.WTGNFTOLP;
                WEAVE = TMV.WTGREAPPI;
                PEGPLAN = TMV.WTGRNAME;
                WTKEY = TMV.WTGSFLG;
            }
        }
        
        public override void LOADBYAUF()
        {
            if (!IsCanLoad)
                return;
            TBMain.Clear();
            if (ORDERNUM.Length < 22)
                return;
            PM["ART"] = ORDERNUM.Substring(1, 20);
            PM["VAR"] = ORDERNUM.Substring(21, 2);
            SResult = TMV.LOADBYWS(PM);
            MergeData(SResult, true);
            if (!IsAuto)
                return;
            if (TBMain.Rows.Count > 0)
                return;
            if (ORDERNUM.Length < 22)
                return;
            PM["ART"] = ORDERNUM.Substring(1, 20);
            PM["VAR"] = ORDERNUM.Substring(21, 2);
            TMV.CREATEBYWS(PM);
            vwMaster.View.MoveCurrentToFirst();
        }
        public override void OnSave()
        {
            if (!IsSaved)
                return;
            if (dwMaster == null)
                return;
            TMV.UpdateWTGEW(dwMaster, app.company, 0);
            base.OnSave();
        }
        public override void OnEdit()
        {
            if (!IsEdit)
                return;
            if (!IsAuto)
                return;
            if (TBMain.Rows.Count > 0)
                return;
            if (ORDERNUM.Length < 22)
                return;
            PM["ART"] = ORDERNUM.Substring(0, 20);
            PM["VAR"] = ORDERNUM.Substring(20, 2);
            TMV.CREATEBYWS(PM);
            vwMaster.View.MoveCurrentToFirst();
            base.OnEdit();
        }

        public virtual void OnGFDISMChg(double value)
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.WTGFDISM = GFDISM;
        }
        public virtual void OnPEGPLANChg()
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.WTGRNAME = PEGPLAN;
             
        }
        public virtual void OnWEAVEChg()
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.WTGREAPPI = WEAVE; 
            
        }
        public virtual void OnWTKEYChg()
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.WTGSFLG = WTKEY; 

        }
        public virtual void OnBINDChg()
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
           // TMV.WTGSFLG = WTKEY; 
        } 
    }
    public partial class UIWTGEW
    {
        #region ==EINZNR===========
        public static readonly DependencyProperty EINZNRProperty = DependencyProperty.Register("EINZNR",
            typeof(string), typeof(UIWTGEW),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnEINZNRChanged));
        public string EINZNR
        {
            get
            {
                return (string)GetValue(EINZNRProperty);
            }
            set
            {
                SetValue(EINZNRProperty, value);
            }
        }
        private static void OnEINZNRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWTGEW;
            if (src != null)
            {
                src.EINZNR = (string)e.NewValue;
            }
        }

        #endregion
        #region ==PEGPLAN===========
        public static readonly DependencyProperty PEGPLANProperty = DependencyProperty.Register("PEGPLAN",
            typeof(string), typeof(UIWTGEW),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPEGPLANChanged));
        public string PEGPLAN
        {
            get
            {
                return (string)GetValue(PEGPLANProperty);
            }
            set
            {
                SetValue(PEGPLANProperty, value);
                OnPEGPLANChg();
            }
        }
        private static void OnPEGPLANChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWTGEW;
            if (src != null)
            {
                src.PEGPLAN = (string)e.NewValue;
            }
        }

        #endregion
        #region ==WEAVE===========
        public static readonly DependencyProperty WEAVEProperty = DependencyProperty.Register("WEAVE",
            typeof(string), typeof(UIWTGEW),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWEAVEChanged));
        public string WEAVE
        {
            get
            {
                return (string)GetValue(WEAVEProperty);
            }
            set
            {
                SetValue(WEAVEProperty, value);
                OnWEAVEChg();
            }
        }
        private static void OnWEAVEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWTGEW;
            if (src != null)
            {
                src.WEAVE = (string)e.NewValue;
            }
        }

        #endregion
        #region ==BIND===========
        public static readonly DependencyProperty BINDProperty = DependencyProperty.Register("BIND",
            typeof(string), typeof(UIWTGEW),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnBINDChanged));
        public string BIND
        {
            get
            {
                return (string)GetValue(BINDProperty);
            }
            set
            {
                SetValue(BINDProperty, value);
                OnBINDChg();
            }
        }
        private static void OnBINDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWTGEW;
            if (src != null)
            {
                src.BIND = (string)e.NewValue;
            }
        }

        #endregion
        #region ==WTKEY===========
        public static readonly DependencyProperty WTKEYProperty = DependencyProperty.Register("WTKEY",
            typeof(string), typeof(UIWTGEW),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWTKEYChanged));
        public string WTKEY
        {
            get
            {
                return (string)GetValue(WTKEYProperty);
            }
            set
            {
                SetValue(WTKEYProperty, value);
                OnWTKEYChg();
            }
        }
        private static void OnWTKEYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWTGEW;
            if (src != null)
            {
                src.WTKEY = (string)e.NewValue;
            }
        }

        #endregion

        #region ==GFDISM===========
        public static readonly DependencyProperty GFDISMProperty = DependencyProperty.Register("GFDISM",
        typeof(double), typeof(UIWTGEW),
        new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnGFDISMChanged));
        public double GFDISM
        {
            get
            {
                return (double)GetValue(GFDISMProperty);
            }
            set
            {
                SetValue(GFDISMProperty, value);
                OnGFDISMChg(value);
            }
        }
        private static void OnGFDISMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWTGEW;
            if (src != null)
            {
                src.GFDISM = (double)e.NewValue;
            }
        }
        #endregion
        #region ==GWBBRT===========
        public static readonly DependencyProperty GWBBRTProperty = DependencyProperty.Register("GWBBRT",
        typeof(double), typeof(UIWTGEW),
        new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnGWBBRTChanged));
        public double GWBBRT
        {
            get
            {
                return (double)GetValue(GWBBRTProperty);
            }
            set
            {
                SetValue(GWBBRTProperty, value);
                OnGWBBRTChg(value);
            }
        }
        private static void OnGWBBRTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWTGEW;
            if (src != null)
            {
                src.GWBBRT = (double)e.NewValue;
            }
        }
        public virtual void OnGWBBRTChg(double value)
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.WTGWBBRT = GWBBRT;
        }
        #endregion
        #region ==GWBF===========
        public static readonly DependencyProperty GWBFProperty = DependencyProperty.Register("GWBF",
        typeof(double), typeof(UIWTGEW),
        new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnGWBFChanged));
        public double GWBF
        {
            get
            {
                return (double)GetValue(GWBFProperty);
            }
            set
            {
                SetValue(GWBFProperty, value);
                OnGWBFChg(value);
            }
        }
        private static void OnGWBFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWTGEW;
            if (src != null)
            {
                src.GWBF = (double)e.NewValue;
            }
        }
        public virtual void OnGWBFChg(double value)
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.WTGWBF = GWBF;
        }
        #endregion

        #region ==FTOLM===========
        public static readonly DependencyProperty FTOLMProperty = DependencyProperty.Register("FTOLM",
        typeof(double), typeof(UIWTGEW),
        new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFTOLMChanged));
        public double FTOLM
        {
            get
            {
                return (double)GetValue(FTOLMProperty);
            }
            set
            {
                SetValue(FTOLMProperty, value);
                OnFTOLMChg(value);
            }
        }
        private static void OnFTOLMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWTGEW;
            if (src != null)
            {
                src.FTOLM = (double)e.NewValue;
            }
        }
        public virtual void OnFTOLMChg(double value)
        {
           
        }
        #endregion

        #region ==FTOLP===========
        public static readonly DependencyProperty FTOLPProperty = DependencyProperty.Register("FTOLP",
        typeof(double), typeof(UIWTGEW),
        new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFTOLPChanged));
        public double FTOLP
        {
            get
            {
                return (double)GetValue(FTOLPProperty);
            }
            set
            {
                SetValue(FTOLPProperty, value);
                OnFTOLPChg(value);
            }
        }
        private static void OnFTOLPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWTGEW;
            if (src != null)
            {
                src.FTOLP = (double)e.NewValue;
            }
        }
        public virtual void OnFTOLPChg(double value)
        {
           
        }
        #endregion

    }

}
